#include <cfenv>
#include <iostream>
#include <string>
#include <math.h>
using std::cout;
using std::endl;
using std::string;
//抽象类
class Figure{
public:
    virtual string getName() const = 0;
    virtual double getArea() const = 0;
};
//长方形
class Rectangle: public Figure{
public:
    Rectangle(double wid, double len)
    :_wid(wid)
    ,_len(len)
    {}

    virtual string getName() const{
        return "Rectangle";
    }
    virtual double getArea() const {
        return _wid * _len;
    }

private:
    double _wid;
    double _len;
};

class Circle:public Figure{
public:
    Circle(double r)
    :_r(r)
    {}

    virtual string getName() const{
        return "Circle";
    }
    virtual double getArea() const{
        return PI * _r *_r;
    }

private:
    double _r;
    const double PI = 3.14;
};

class Triangle:public Figure{
public:
    Triangle(double a,double b,double c)
    :_a(a)
    ,_b(b)
    ,_c(c)
    {}
    virtual string getName() const{
        return "Triangle";
    }
    virtual double getArea() const{
        double p = (_a + _b + _c)/2;
        return sqrt(p*(p-_a)*(p-_b)*(p-_c));
    }

private:
    double _a,_b,_c;
};

void display(Figure & fig){
    cout << fig.getName()
        <<"的面积是:"
        <<fig.getArea() <<endl;
}

void test(){
    Rectangle r(10,20);
    Circle c(15);
    Triangle t(3,4,5);
    display(r);
    display(c);
    display(t);
}

int main()
{
    test ();
    return 0;
}

